package com.zbu.bigdecimal;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalDemo {
    public static void main(String[] args) {
        BigDecimal bd1 = BigDecimal.valueOf(-10);
        BigDecimal bd2 = BigDecimal.valueOf(3);

        BigDecimal result1 = bd1.divide(bd2, 2, RoundingMode.UP);       //3.34  进一法
        BigDecimal result2 = bd1.divide(bd2, 2, RoundingMode.DOWN);     //3.33  去尾法
        BigDecimal result3 = bd1.divide(bd2, 2, RoundingMode.HALF_UP);  //3.33  四舍五入
        System.out.println(result1);
        System.out.println(result2);
        System.out.println(result3);

        double v = result1.doubleValue();   //由于调用divide方法后返回得值的类型是BigDecimal，无法进行运算操作所以需要改变类型
        System.out.println(Math.abs(v));
    }

}
